package org.cloudie.docs.editor.client.events;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;

import java.util.Date;

public abstract class DoubleClickHandler implements ClickHandler {
  
  private final double threshold = 500;
  private double lastClick = 0;

  public void onClick(ClickEvent event) {
    double curClick = new Date().getTime();
    double diff = curClick - lastClick;
    if (diff < threshold) {
      onDoubleClick(event);
    } else {
      lastClick = curClick;
    }
  }
  
  public abstract void onDoubleClick(ClickEvent event);
  
}
